package com.banyuan.课堂练习.Thread.线程池;

/*
 * 刷牙（2）
 * 烧水（5）
 * 洗脸（2）
 * 煮鸡蛋（5）
 * 吃鸡蛋（2）
 * */
public class GetUp {
    public static void main(String[] args) throws InterruptedException {
        long start = System.currentTimeMillis();
        System.out.println("起床喽！");
        Thread th1 = new Thread() {
            @Override
            public void run() {
                brushTeeth();
                washFace();
                eatEggs();
            }
        };

        Thread th2 = new Thread() {
            @Override
            public void run() {
                cookEggs();
                boilWater();
            }
        };

        th1.start();
        th2.start();
        th1.join();
        th2.join();

        long end = System.currentTimeMillis();
        System.out.println("耗时" + (end - start) / 1000 + "秒");


    }

    public static void brushTeeth() {
        try {
            Thread.sleep(2000);
            System.out.println("刷牙；");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void boilWater() {
        try {
            Thread.sleep(5000);
            System.out.println("烧水；");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void washFace() {
        try {
            Thread.sleep(2000);
            System.out.println("洗脸；");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void cookEggs() {
        try {
            Thread.sleep(5000);
            System.out.println("煮鸡蛋；");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void eatEggs() {
        try {
            Thread.sleep(2000);
            System.out.println("吃鸡蛋；");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
